package com.store.serviceimpl;


import com.store.mapper.UserMapper;
import com.store.pojo.User;
import com.store.service.UserService;
import com.store.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    /**
     * 根据用户名查询当前用户信息
     */
    @Override
    public JsonResult findUserByUsername(String username) {
        JsonResult jsonResult = new JsonResult();
        if (username == null || "".equals(username)) {
            jsonResult.setState(201);
            jsonResult.setMsg("注册名必填");
            return jsonResult;
        }
        User user = userMapper.findUserByUsername(username);
        if (user != null) {
            jsonResult.setState(202);
            jsonResult.setMsg("用户名被占用");
            return jsonResult;
        }
        //jsonResult = new JsonResult(200,"用户名可用");
        jsonResult.setState(200);
        jsonResult.setMsg("用户名可用");
        return jsonResult;
    }


}
